--
-- Author: shunguo.chen
-- Date: 2016-08-09 13:53:57
--
-- RewardInvestRender

local ClassRef = app.mvc.createRenderClass(...)

--data = RewardInvestVo
function ClassRef.create(data, node)
	local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.RewardInvestNode))
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init(data)
	return sprite
end       

function ClassRef:init(data)
	self.super.init(self, data)

	self:setContentSize(self._ui.bonus:getContentSize())
	self._ui.Button:addClickEventListener(function()
			executeFunc(self._onBtnClick)
		end)
	self:refresh()
end

function ClassRef:refresh()
	if self._data then
		self._ui.note:setString(string.format(L("tips_2000234"), self._data.lv))
		self._ui.num:setString(self._data.coins)
		self._ui.img:loadTexture(self._data.icon)
		
		if self._data.able then
			local str = L("tips_2000235")
			local able = false
			if self._data.got then
				str = L("tips_2000236")
			else
				able = self._data:isLevAble()
				if not self._data:isLevAble() then
					str = L("tips_2000237")
				end
			end
			self._ui.name:setString(str)
			self._ui.Button:setTouchEnabled(able)
			self._ui.Button:setBright(able)
		else
			self._ui.Button:setTouchEnabled(false)
			self._ui.Button:setBright(false)
		end
	end
end

function ClassRef:onBtnClick(cb)
	self._onBtnClick = cb
end

return ClassRef